package com.jar.exercise.集合和数据结构.对hashmap排序;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author ZhangShengHao
 * @className Demo1
 * @description TODO
 * @date 2020/1/13 18:05
 */
public class Demo {

	public static void main(String[] args) {
		HashMap<String, Student> map = new HashMap<>();
		map.put("1003", new Student(12, "Sam"));
		map.put("1005", new Student(13, "Joseph"));
		map.put("1007", new Student(21, "Kate"));
		map.put("1002", new Student(7, "Miranda"));
		map.put("1004", new Student(6, "Peter"));
		for (Map.Entry<String, Student> e : map.entrySet()) {
			System.out.println(e.getKey() + ":" + e.getValue());
		}
		System.out.println("--------------------------------------");
		TreeMap<String, Student> sortedMap = new TreeMap<>(map);
		for (Map.Entry<String, Student> e : sortedMap.entrySet()) {
			System.out.println(e.getKey() + ":" + e.getValue());
		}
	}
}
